package de.koller.reason.gui.component.textfield;

import de.koller.oceanFramework.glyph.GlyphRendererGL;
import de.koller.oceanFramework.glyph.GlyphScreen;
import de.koller.reason.gui.GUIRoot;
import de.koller.reason.gui.component.button.RButton;
import de.koller.reason.gui.component.mo.GlowMode;
import de.koller.reason.gui.renderObj.GlyphRendering;
import de.koller.reason.gui.renderObj.IRenderObject;
import de.koller.reason.gui.renderObj.IVolatileRenderObject;
import de.koller.reason.gui.textureObj.IPart;
import java.util.Set;

public class RTextField extends RButton implements IVolatileRenderObject {

	private final int length;
	private final GlyphRendering volatileRendering;
	
	public RTextField( IPart renderPart, GlyphRendering volatileRendering ) {
		super( renderPart, GlowMode.Always );
		length = (int)(renderPart.getSubWidth() / GlyphScreen.GLYPH_WIDTH);
		this.volatileRendering = volatileRendering;
		
		this.setGlowRange( 3 );
		this.setColorGlow( 0xffffff00 );
	}

	@Override
	public void renderFrame() {
		int gx = (int)(this.getSubPart().getSubX() / GlyphScreen.GLYPH_WIDTH);
		int gy = (int)(this.getSubPart().getSubY() / GlyphScreen.GLYPH_HEIGHT);
		
		for( int x = 0; x < length; x++ ) {
			GlyphRendererGL r = volatileRendering.getRenderer();
			r.setCurrentBackColor( 0xff101010 );
			
			r.renderGlyph( gx+x, gy, -1, -1 );
		}
	}
	
	@Override
	public void addTo( GUIRoot gui, Set<IRenderObject> renderSet ) {
		super.addTo( gui, renderSet );
		gui.textFieldHandler.addTextField( this );
	}

	@Override
	public void removeFrom( GUIRoot gui ) {
		super.removeFrom( gui );
		gui.textFieldHandler.removeTextField( this );
	}
	
	
	
}
